/*************************************************************************
	> File Name: 006.根据n值添加括号.c
	> Author: Maureen 
	> Mail: Maureen@qq.com 
	> Created Time: 三  8/18 18:57:55 2021
 ************************************************************************/

#include <stdio.h>

//根据n值不同，加不同的括号{[{str}]}

#define swap(a, b) { \
    __typeof(a) __temp = a; \
    a = b;\
    b = __temp;\
}

int main() {
    int n;
    scanf("%d", &n);
    char str[100] = {0};
    sprintf(str, "%d.%d.%d.%d", 192, 168, 0, 1);
    printf("%s\n", str);

    char buffer[1000] = {0};
    char *p = str;
    char *q = buffer;
    //判断文件权限(n值)，拼接括号
    if (n & 1) {
        sprintf(q, "{%s}", p); //p = 192.168.0.1, q = {192.168.0.1}
        swap(p, q); //p = {192.168.0.1}, q = 192.168.0.1
    }

    if (n & 2) {
        sprintf(q, "[%s]", p);
        swap(p, q);
    }

    if (n & 4) {
        sprintf(q, "{%s}", p);
        swap(p, q);
    }
    printf("p: %s\n", p);

    FILE *fout = fopen("output", "w"); //会新建文件output
    fprintf(fout, "str = %s\n", p);
    fprintf(stdout, "stdout = %s\n", p);
    fprintf(stderr, "stderr = %s\n", p);

    return 0;
}
/*
测试结果：
7 //输入
192.168.0.1
p: {[{192.168.0.1}]}
stdout = {[{192.168.0.1}]}
stderr = {[{192.168.0.1}]}
 */
